//
//  APCopyControl.m
//  AqualPolo
//
//  Created by dong on 2024/5/8.
//

#import "APCopyControl.h"
#import "APLoginManager.h"
@implementation APCopyControl

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = LYRGBColor(8, 23, 78);
        self.layer.cornerRadius = 8;
        self.layer.masksToBounds = true;
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = UIColor.whiteColor;
        _titleLabel.font = [LYFont fontWithSize:12 fontName:LYFontNamepfr];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        [_titleLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_titleLabel setContentCompressionResistancePriority:UILayoutPriorityFittingSizeLevel forAxis:UILayoutConstraintAxisHorizontal];
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(20);
            make.top.bottom.equalTo(self);
        }];
        
        _apButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_apButton setTitle:@"Copy" forState:UIControlStateNormal];
        _apButton.titleLabel.font = [LYFont fontWithSize:10 fontName:LYFontNamepfr];
        [_apButton setTitleColor:LYRGBColor(87, 61, 255) forState:UIControlStateNormal];
        _apButton.backgroundColor = LYRGBColor(158, 253, 223);
        _apButton.layer.cornerRadius = 4;
        _apButton.layer.masksToBounds = true;
        [_apButton addTarget:self action:@selector(copyButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_apButton];
        [_apButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-20);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(32, 14));
        }];
    }
    return self;
}


- (void)copyButtonDidClick:(UIButton *)sender{
    APUserModel *userModel = [[APLoginManager shareInstance] userInfo];
    [UIPasteboard generalPasteboard].string = userModel.userId;
    [self.superview ShowProgressOnlyLabel:@"copy success"];
}

@end
